#include <iostream>
# include <fstream>
#include <string>
#include <strstream>
#include <string.h>

using namespace std;

int main() {
    //book q4
    ofstream file1("data1.txt", ios::trunc);
    string s;
    for (int i = 0; i <= 20; i++) {
        s = to_string(i);
        for (int j = 0; j < s.length(); j++) {
            file1.put(s[j]);
        }
        file1.put(' ');
    }
    file1.close();

    //book q5
    int c;
    ofstream file2("data2.dat", ios::trunc | ios::binary);
    string ss;
    for (int i = 1; i <= 50; i++) {
        int ii = 2 * i - 1;
        file2.write((char *) &ii, sizeof(ii));
    }
    file2.close();
    ifstream file3("data2.dat", ios::binary);
    for (int i = 0; !file3.eof(); i++) {
        file3.read((char *) &c, sizeof(int));
        cout << c << ' ';
    }
    cout << endl;

    //book q6
    char in[50];
    char out[50];
    istrstream ins(in, sizeof(in));
    ostrstream outs(out, sizeof(out));
//    cin.getline(in,sizeof (in));
    strcpy(in, "123adwd1234@");
    char seek = ' ';
    int n;
    while (seek != '@') {
        if (seek >= 48 && seek <= 57) {
            ins.putback(seek);
            ins >> n;
            outs << n << ',';

        }
        ins.get(seek);
    }
    outs << '@' << endl;
    cout << out;

    //book q7
    int num = 0;
    float vec[num];
    for (int i = 0; i < num; i++) {
        cin >> vec[i];
    }
    ofstream file4("data.txt", ios::trunc);
    for (int i = 0; i < num; i++) {
        file4.write((char *) &vec[i], sizeof(vec[i]));
    }
    file4.close();
    ifstream file5("data.txt");
    float vec2[num];
    for (int i = 0; i < num; i++) {
        file5.read((char *) &vec2[i], sizeof(vec2[i]));
    }
    float max = vec2[0], min = vec2[0], max_p = 0, min_p = 0;
    for (int i = 0; i < num; i++) {
        if (vec2[i] > max) {
            max_p = i;
            max = vec2[i];
        }

        if (vec2[i] < min) {
            min_p = i;
            min = vec2[i];
        }
    }
    cout << max << " " << max_p << endl;
    cout << min << " " << min_p << endl;
    for (int i = 0; i < num - 1; i++) {
        for (int j = i + 1; j < num; j++) {
            if (vec2[i] > vec2[j]) {
                float temp = vec2[j];
                vec2[j] = vec2[i];
                vec2[i] = temp;
            }
        }
    }
    for (int i = 0; i < num; i++) {
        cout << vec2[i] << " ";
    }
    cout << endl;


    return 0;
}